package com.interviewbackend.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.interviewbackend.entity.InterviewRecord;
import com.interviewbackend.mapper.InterviewRecordMapper;
import com.interviewbackend.service.InterviewRecordService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InterviewRecordServiceImpl extends ServiceImpl<InterviewRecordMapper, InterviewRecord>
        implements InterviewRecordService {

    @Override
    public List<InterviewRecord> getMainAiRecords(Long interviewId, int roundIndex) {
        return this.list(new QueryWrapper<InterviewRecord>()
                .eq("interview_id", interviewId)
                .eq("round_index", roundIndex)
                .eq("is_ai", true)
                .eq("is_follow_up", false)
                .orderByAsc("id"));
    }

    @Override
    public InterviewRecord getLastAiRecord(Long interviewId) {
        List<InterviewRecord> records = this.list(new QueryWrapper<InterviewRecord>()
                .eq("interview_id", interviewId)
                .eq("is_ai", true)
                .orderByDesc("id")
                .last("LIMIT 1"));

        return records.isEmpty() ? null : records.get(0);
    }
}
